package com.huijinhui.wlmtsys.controller;


import com.huijinhui.wlmtsys.constant.JwtClaimsConstant;
import com.huijinhui.wlmtsys.enums.AppHttpCodeEnum;
import com.huijinhui.wlmtsys.pojo.dtos.LoginFormDTO;
import com.huijinhui.wlmtsys.pojo.dtos.PageDTO;
import com.huijinhui.wlmtsys.pojo.dtos.ResponseResult;
import com.huijinhui.wlmtsys.pojo.entity.*;
import com.huijinhui.wlmtsys.pojo.vo.UserLoginVO;
import com.huijinhui.wlmtsys.properties.JwtProperties;
import com.huijinhui.wlmtsys.service.InfoService;
import com.huijinhui.wlmtsys.service.UserService;
import com.huijinhui.wlmtsys.utils.JwtUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Tag(name = "admin-----实验室简介接口")
@RestController
@RequestMapping("/info")
@RequiredArgsConstructor
@Slf4j
public class InfoController {

    @Autowired
    private InfoService infoService;


    @Operation(summary = "admin+官网---实验室简介查询接口")
    @GetMapping("/intro")
    public ResponseResult getLabIntro() {
        log.info("实验室简介接口");
        List<WlmtsysInfo> list = infoService.getLabIntro();
        return ResponseResult.okResult(list);
    }

    @Operation(summary = "admin---添加实验室简介接口")
    @PostMapping("/add")
    public void addLabInfo(@RequestBody WlmtsysInfo wlmtsysInfo) {
        log.info("添加实验室简介接口");
        infoService.addLabInfo(wlmtsysInfo);
    }


    @Operation(summary = "admin---根据id获取实验室简介接口")
    @GetMapping("/{id}")
    public ResponseResult getLabInfo(@PathVariable("id") Integer id) {
        log.info("获取实验室简介接口");
        WlmtsysInfo wlmtsysInfo = infoService.getLabInfo(id);
        return ResponseResult.okResult(wlmtsysInfo);
    }


    @Operation(summary = "admin---删除实验室简介接口")
    @DeleteMapping("/delete/{id}")
    public void deleteLabInfo(@PathVariable("id") Integer id) {
        log.info("删除实验室简介接口");
        infoService.deleteLabInfo(id);
    }


    @Operation(summary = "admin---图片接口1")
    @PostMapping("/upload")
    public ResponseResult uploadNews(@RequestParam("file") MultipartFile multipartFile, @RequestParam("id") Integer imageId) {
        log.info("图片接口,{},id:{}", multipartFile, imageId);
        infoService.uploadNews(multipartFile, imageId);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
    @Operation(summary = "admin---图片接口2")
    @PostMapping("/upload/weimg")
    public ResponseResult uploadNewsWe(@RequestParam("file") MultipartFile multipartFile, @RequestParam("id") Integer weimgId) {
        log.info("图片接口,{},id:{}", multipartFile, weimgId);
        infoService.uploadNewsWe(multipartFile, weimgId);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @Operation(summary = "admin---修改实验室简介接口")
    @PutMapping("/update")
    public void updateLabInfo(@RequestBody WlmtsysInfo wlmtsysInfo) {
        log.info("修改实验室简介接口");
        infoService.updateLabInfo(wlmtsysInfo);
    }

    @Operation(summary = "admin---分页 获取信息接口")
    @GetMapping("/page")
    public PageDTO<WlmtsysInfo> queryNewsPage(PageQuery query){
        log.info("分页 获取信息接口");
        return infoService.queryEmployPage(query);
    }
}

